<template>
	<view class="container-bottom-btns">
		<view class="form">
			<view class="form-column-item">
				<view class="label">
					运费价格
				</view>
				<view class="content">
					<input type="digit" placeholder="请设置运费" v-model="form.price"/>
				</view>
			</view>
		</view>
		
		<view class="bottom-btn-wrapper">
			<SubmitBtn text="保存" @tap="setPostage"></SubmitBtn>
		</view>
	</view>
</template>

<script>
	import { toast } from '../../utils/uni-api';
import validate from '../../utils/validate';
import { getProductDetail, setPostage } from '@/api/product.js'
	export default {
		data() {
			return {
				form: {
					id: '',
					price: ''
				}
			};
		},
		onLoad(option){
			this.form.id = option.id || ''
			getProductDetail({id: this.form.id}).then(res => {
				this.form.price = res.result.postage_price
			})
		},
		methods:{
			setPostage(){
				if(!validate.isNotEmpty(this.form.price, '运费价格'))return
				if(!validate.isNotZero(this.form.price, '运费价格'))return
				this.form.price = Number(this.form.price)
				setPostage(this.form).then(res => {
					toast(res.message, true)
					setTimeout(() => {
						uni.navigateBack()
					}, 500)
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
